//
//  DetailHealthReportsViewController.m
//  JiuLe
//
//  Created by SunChao on 16/9/27.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "DetailHealthReportsViewController.h"
#import "NSString+Helper.m"
#import "BaseDataRequest.h"
#import "PNChart.h"
#import "PNChartDelegate.h"
#import "NSString+Helper.h"
#import "AnalysisHealthReport.h"
#import <Masonry.h>
#import "ShareObjectSingleton.h"
#define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#define RGBAColor(r, g, b ,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
#define RandColor RGBColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))
@interface DetailHealthReportsViewController ()<UITableViewDelegate,UITableViewDataSource,PNChartDelegate>
@property (nonatomic,strong)NSMutableDictionary *params;
@property (nonatomic,strong)NSMutableArray *activity;
@property (nonatomic,strong)NSMutableArray *breath;
@property (nonatomic,strong)NSMutableArray *heartrate;
@property (nonatomic,strong)NSMutableArray *skintemp;
@property (nonatomic,strong)NSMutableArray *sleep;
@property (nonatomic,strong)NSMutableArray *blood;
@property (nonatomic,strong)NSMutableArray *spo2;
@property (nonatomic,strong)NSMutableArray *warn;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UILabel *detailLabel;
@property (nonatomic) PNLineChart * lineChart;
@property (nonatomic,strong)NSMutableArray *dataArr;
@property (nonatomic,strong)NSMutableDictionary *textDic;
@property (nonatomic,strong)NSMutableArray *heightArr;
@end

@implementation DetailHealthReportsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self CreateUI];
    [self showNavgationWithLeftItemWithTitle:@"返回"];
    [self requestDataSource];
}
#pragma  获取数据信息
- (void)requestDataSource
{
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"YYYY-MM-dd"];
    NSDate* date = [formater dateFromString:self.startDateString];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate: date];
    NSDate *startDate = [date  dateByAddingTimeInterval: interval];
    int i = 6;
    NSDate *endDate = [NSDate dateWithTimeInterval:24*60*60*i sinceDate:startDate];
    NSString *startDateStr =[formater stringFromDate:startDate];
    NSString *endDateStr =[formater stringFromDate:endDate];
    NSString *user_id = [[NSUserDefaults standardUserDefaults] objectForKey:@"userID"];
    self.params = [NSMutableDictionary new];
    [self.params setValue:user_id forKey:@"user_id"];
    [self.params setValue:startDateStr forKey:@"start_date"];
    [self.params setValue:endDateStr forKey:@"end_date"];
    [[BaseDataRequest alloc] getNewestDetailedHealthData:self.params WithBlock:^(id responseObject, NSString *status, NSError *error) {
        if (error) {
            NSLog(@"error:%@",error);
        }else
        {
            NSDictionary *result = [responseObject objectForKey:@"result"];
            NSDictionary *detail = [result objectForKey:@"detail"];
            if (detail.count>0) {
                self.activity = [NSMutableArray new];
                self.breath = [NSMutableArray new];
                self.heartrate = [NSMutableArray new];
                self.skintemp = [NSMutableArray new];
                self.sleep = [NSMutableArray new];
                self.spo2 = [NSMutableArray new];
                self.warn = [NSMutableArray new];
                self.textDic = [NSMutableDictionary new];
                if ([detail.allKeys containsObject:@"activity"]) {
                    self.activity = [detail objectForKey:@"activity"];
                }
                if ([detail.allKeys containsObject:@"breath"]) {
                    self.breath = [detail objectForKey:@"breath"];
                }
                if ([detail.allKeys containsObject:@"heartrate"]) {
                    self.heartrate = [detail objectForKey:@"heartrate"];
                }
                if ([detail.allKeys containsObject:@"skintemp"]) {
                    self.skintemp = [detail objectForKey:@"skintemp"];
                }
                if ([detail.allKeys containsObject:@"sleep"]) {
                    self.sleep = [detail objectForKey:@"sleep"];
                }
                if ([detail.allKeys containsObject:@"spo2"]) {
                    self.spo2 = [detail objectForKey:@"spo2"];
                }
                if ([detail.allKeys containsObject:@"warn"]) {
                    self.warn = [detail objectForKey:@"warn"];
                }

                if ([detail.allKeys containsObject:@"heartrate"]) {
                    [self.textDic setObject:[detail objectForKey:@"activity_desc"] forKey:@"activity_desc"];
                    [self.textDic setObject:[detail objectForKey:@"breath_desc"] forKey:@"breath_desc"];
                    [self.textDic setObject:[detail objectForKey:@"heartrate_desc"] forKey:@"heartrate_desc"];
                    [self.textDic setObject:[detail objectForKey:@"skintemp_desc"] forKey:@"skintemp_desc"];
                    [self.textDic setObject:[detail objectForKey:@"sleep_desc"] forKey:@"sleep_desc"];
                    [self.textDic setObject:[detail objectForKey:@"spo2_desc"] forKey:@"spo2_desc"];
                    [self.textDic setObject:[detail objectForKey:@"warn_desc"] forKey:@"warn_desc"];
                }
            }
        }
        [self performSelectorOnMainThread:@selector(reloadUIData) withObject:nil waitUntilDone:YES];
    }];
    
}
- (void)CreateUI
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = RGB(239, 238, 244);
    [self.view addSubview:self.tableView];
}
- (void)reloadUIData
{
    NSArray *array = @[@"warn_desc",@"activity_desc",@"sleep_desc",@"heartrate_desc",@"spo2_desc",@"breath_desc",@"skintemp_desc"];
    self.heightArr = [NSMutableArray new];
    for (int i = 0; i<array.count; i++) {
        NSString *str1 = [self.textDic objectForKey:array[i]];
        CGSize detailSize = [str1 sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(self.view.frame.size.height-40, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
        NSNumber *height =  [NSNumber numberWithFloat:detailSize.height];
        [self.heightArr addObject:height];
    }
    NSLog(@"heightArr:%@",self.heightArr);
    [self.tableView reloadData];
}

#pragma mark - TableView datasource&delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 7;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSNumber *height = [self.heightArr objectAtIndex:indexPath.section];
    float H = [height floatValue];
    return 300+H;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"CellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"YYYY-MM-dd"];
    NSDate* date = [formater dateFromString:self.startDateString];
    NSArray *Xarray = [self getAfterSevenDaysWithStartDate:date];
    UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(20,20,SCREEN_WIDTH-40,35)];
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 35, 35)];
    [titleView addSubview:imgView];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 0, 200, 35)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = RGB(75, 162, 200);
    [titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
    [titleView addSubview:titleLabel];
    self.lineChart =[[PNLineChart alloc] initWithFrame:CGRectMake(20, 80, SCREEN_WIDTH-40, 200.0)];
    self.lineChart.delegate = self;
    UILabel *detailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 280, SCREEN_WIDTH-40, 999)];
    detailLabel.backgroundColor = [UIColor clearColor];
    detailLabel.numberOfLines = 0;
    detailLabel.font = [UIFont systemFontOfSize:13];
    detailLabel.textColor = RGB(144, 144, 144);
    detailLabel.text = NSTextAlignmentLeft;
    NSArray *array = @[@"一周健康预警趋势",@"一周计步趋势",@"一周睡眠趋势",@"一周心率趋势",@"一周血氧趋势",@"一周呼吸趋势",@"一周体温趋势"];
    NSArray *imgArray = @[@"三级预警趋势",@"计步趋势",@"睡眠趋势",@"心率趋势",@"血氧趋势",@"呼吸趋势",@"体温趋势"];
//    if (cell == nil) {
        cell = [[UITableViewCell alloc]init];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",imgArray[indexPath.section]]];
        titleLabel.text = [NSString stringWithFormat:@"%@",array[indexPath.section]];
        [cell addSubview:titleView];
        [cell addSubview:self.lineChart];
        [cell addSubview:detailLabel];
        switch (indexPath.section) {
            
            case 1://步数（0——1000||1k——5k）
            {
               //获取数组的最大值
                NSArray *DescArr = [self sortedArrayWithArray:self.activity];
                //取数组中的平均值
                int  avg = [[DescArr valueForKeyPath:@"@avg.floatValue"]intValue];
                     detailLabel.text =  [self.textDic objectForKey:@"activity_desc"];
                //判断计步数量级是否大于1000 如果大于则用K为单位 如果
                NSString *str = [DescArr lastObject];
                int maxNum = [str intValue];
                int YmaxNum = 0;
                if (maxNum<1000) {
                     YmaxNum = (maxNum+50)/50*50;
                }else
                {
                    YmaxNum = (maxNum+500)/500*500;
                }
                
                NSMutableArray *Yarray = [self WalkCalculateYWithMaxNum:YmaxNum];
                if (avg ==0) {
                    NSArray *Yarr = @[@"0",@"100",@"200",@"300",@"400"];
                    [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarr yFixedValueMax:400 YFixedValueMin:0 withFirstLineDataSourse:self.activity WithHighLineNum:0 WithLowLineNum:0];
                }else
                {
                [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:YmaxNum YFixedValueMin:0 withFirstLineDataSourse:self.activity WithHighLineNum:0 WithLowLineNum:0];
                }
                detailLabel.text  = [self.textDic objectForKey:@"activity_desc"];
                [detailLabel sizeToFit];
            }
                break;
            case 5://呼吸(0——30)
            {
                //标准值
                int standardH = 25;
                int standardL = 12;
                NSMutableArray *Yarray = [self CalculateYWithHigh:standardH andLow:standardL andArray:self.breath];
                int max = [[Yarray lastObject]intValue];
                int min = [[Yarray firstObject]intValue];
                [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:max YFixedValueMin:min withFirstLineDataSourse:self.breath WithHighLineNum:standardH WithLowLineNum:standardL];
                if (self.breath.count>0) {
                    //保存平均值，超过25的次数，低于12的次数
                    //float avg = [[self.breath valueForKeyPath:@"@avg.floatValue"]floatValue];
                    int Hi = 0,Li = 0;
                    for (NSString  *num in self.breath) {
                        if ([num intValue]>25) {
                            Hi++;
                        }
                        if ([num intValue]<12) {
                            Li ++;
                        }
                    }
                   
                }
                detailLabel.text  = [self.textDic objectForKey:@"breath_desc"];
                [detailLabel sizeToFit];
            }
                break;
            case 3://心率（0——180）
            {
                //标准值
                int standardH = 120;
                int standardL = 60;
                NSMutableArray *Yarray = [self CalculateYWithHigh:standardH andLow:standardL andArray:self.heartrate];
                int max = [[Yarray lastObject]intValue];
                int min = [[Yarray firstObject]intValue];
                [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:max YFixedValueMin:min withFirstLineDataSourse:self.heartrate WithHighLineNum:standardH WithLowLineNum:standardL];
                if (self.heartrate.count>0) {
                    
                    //float avg = [[self.heartrate valueForKeyPath:@"@avg.floatValue"]floatValue];
                    int Hi = 0,Li = 0;
                    for (NSString *num in self.heartrate) {
                        if ([num intValue]>100) {
                            Hi++;
                        }
                        if ([num intValue]<60) {
                            Li ++;
                        }
                    }
                   
                }
                detailLabel.text  = [self.textDic objectForKey:@"heartrate_desc"];
                [detailLabel sizeToFit];
                NSLog(@"detailLabel:%@",detailLabel.text);
            }
                break;
            case 6://体温(0——42.C)
            {
                //标准值
                int standardH = 37;
                int standardL = 30;
                NSMutableArray *Yarray = [self CalculateYWithHigh:standardH andLow:standardL andArray:self.skintemp];
                int max = [[Yarray lastObject]intValue];
                int min = [[Yarray firstObject]intValue];
                 [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:max YFixedValueMin:min withFirstLineDataSourse:self.skintemp WithHighLineNum:standardH WithLowLineNum:standardL];
                if (self.skintemp.count>0) {
                    //float avg = [[self.skintemp valueForKeyPath:@"@avg.floatValue"]floatValue];
                    NSArray *tmpArr = [self.skintemp sortedArrayUsingSelector:@selector(compare:)];
                    max = [[tmpArr lastObject ]intValue];
                    min = [[tmpArr firstObject]intValue];
                  
                }
                 detailLabel.text  =  [self.textDic objectForKey:@"skintemp_desc"];
                [detailLabel sizeToFit];
            }
                break;
            case 4://血氧（0——100%）
            {
                //标准值
                int standardH = 100;
                int standardL = 90;
                 NSMutableArray *Yarray = [self CalculateYWithHigh:standardH andLow:standardL andArray:self.spo2];
                int max = [[Yarray lastObject]intValue];
                int min = [[Yarray firstObject]intValue];
                //NSNumber *avg = [self.spo2 valueForKeyPath:@"@avg.floatValue"];
                [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:max YFixedValueMin:min withFirstLineDataSourse:self.spo2 WithHighLineNum:standardH WithLowLineNum:standardL];
                if (self.spo2.count>0) {
                    //NSArray *tmpArray = [self.spo2 sortedArrayUsingSelector:@selector(compare:)];
                    //int L = [[tmpArray firstObject]intValue];
                    int Li = 0;
                    for (NSString *str  in self.spo2) {
                        if ([str intValue]<70) {
                            Li++;
                        }
                    }
                  
                }
                 detailLabel.text = [self.textDic objectForKey:@"spo2_desc"];
                [detailLabel sizeToFit];
            }
                break;
            case 2://睡眠（0——12）
            {
                NSMutableArray *effecArr = [NSMutableArray new];
                NSMutableArray *roverArr = [NSMutableArray new];
                NSMutableArray *totalArr = [NSMutableArray new];
               
                for (NSDictionary *tmpDic in self.sleep) {
                    if ([tmpDic.allKeys containsObject:@"sleep_effective_time"]&&[tmpDic.allKeys containsObject:@"sleep_rover_time"]&&[tmpDic.allKeys containsObject:@"sleep_total_time"]) {
                        [effecArr addObject:[NSNumber numberWithFloat:[[tmpDic objectForKey:@"sleep_effective_time"]intValue]/60.0]];
                        [roverArr addObject:[NSNumber numberWithFloat:[[tmpDic objectForKey:@"sleep_rover_time"]intValue]/60.0]];
                        [totalArr addObject:[NSNumber numberWithFloat:[[tmpDic objectForKey:@"sleep_total_time"]intValue]/60.0]];
                        
                    }
                }
                //标准值
                int standardH = 8;
                int standardL = 6;
                NSMutableArray *Yarray = [self CalculateYWithHigh:standardH andLow:standardL andArray:totalArr];
                int max = [[Yarray lastObject]intValue];
                int min = [[Yarray firstObject]intValue];
                //float avg = [[totalArr valueForKeyPath:@"@avg.floatValue"]floatValue];
                int Li=0,Hi=0;
                for (NSString *tmp in totalArr) {
                    if ([tmp floatValue]<6.0) {
                        Li++;
                    }
                    if ([tmp floatValue]>8.0) {
                        Hi++;
                    }
                }
                [self.lineChart linechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:max YFixedValueMin:min withFirstLineDataSourse:effecArr withSecondLineDataSourse:roverArr withthThirdLineDataSourse:totalArr WithHighLineNum:standardH WithLowLineNum:standardL];
                    UIView *legend = [self.lineChart getLegendWithMaxWidth:320];
                    [legend setFrame:CGRectMake(self.view.frame.size.width-100, 40, legend.frame.size.width, legend.frame.size.height)];
                    [cell addSubview:legend];
                   detailLabel.text = [self.textDic objectForKey:@"sleep_desc"];
                [detailLabel sizeToFit];
            }
                break;
            case 0:
            {
                NSMutableArray *onenotice = [NSMutableArray new];
                NSMutableArray *twonotice = [NSMutableArray new];
                NSMutableArray *threenotice = [NSMutableArray new];
                
                for (NSDictionary *tmpDic in self.warn) {
                    if ([tmpDic.allKeys containsObject:@"onenotice"]&&[tmpDic.allKeys containsObject:@"twonotice"]&&[tmpDic.allKeys containsObject:@"threenotice"]) {
                        [onenotice addObject:[tmpDic objectForKey:@"onenotice"]];
                        [twonotice addObject:[tmpDic objectForKey:@"twonotice"]];
                        [threenotice addObject:[tmpDic objectForKey:@"threenotice"]];
                    }
                }
                //计算最大值和最小值
                NSMutableArray *bigArr = [NSMutableArray new];
                for (int i = 0; i<onenotice.count; i++) {
                    [bigArr addObject:[onenotice objectAtIndex:i]];
                    [bigArr addObject:[twonotice objectAtIndex:i]];
                    [bigArr addObject:[threenotice objectAtIndex:i]];
                }
                [bigArr sortUsingSelector:@selector(compare:)];
                NSLog(@"bigArr:%@",bigArr);
                float maxNum = [[bigArr lastObject]floatValue];
                float minNum = [[bigArr firstObject]floatValue];

                NSArray *Yarray = [self CalculateYWithHigh:maxNum andLow:minNum andArray:bigArr];
                int max = [[Yarray lastObject]intValue];
                int min = [[Yarray firstObject]intValue];
                //没有数据
                if (bigArr.count ==0) {
                    Yarray = @[@"0",@"2",@"4",@"6",@"8"];
                }
                [self.lineChart YJlinechar:self.lineChart WithXLabels:Xarray YLabels:Yarray yFixedValueMax:max YFixedValueMin:min withFirstLineDataSourse:onenotice withSecondLineDataSourse:twonotice withthThirdLineDataSourse:threenotice WithHighLineNum:0 WithLowLineNum:0];
                        UIView *legend = [self.lineChart getLegendWithMaxWidth:320];
                        [legend setFrame:CGRectMake(self.view.frame.size.width-100, 40, legend.frame.size.width, legend.frame.size.height)];
                        [cell addSubview:legend];
                detailLabel.text = [self.textDic objectForKey:@"warn_desc"];
                [detailLabel sizeToFit];
            }
            default:
                break;
        }
//    }
    
    return cell;
    
}
#pragma 获取最大值最小值和平均值
- (NSMutableDictionary *)analyseDataWith:(NSMutableArray *)array
{
    NSMutableDictionary *dic  = [NSMutableDictionary new];
    if (array.count==0) {
        return nil;
    }else
    {
        //对数据排序(默认升序)
        NSArray *tmpArr = [NSArray new];
        tmpArr = [array sortedArrayUsingSelector:@selector(compare:)];
        //平均值P
        NSNumber *P = [tmpArr valueForKeyPath:@"@avg.floatValue"];
        [dic setObject:P forKey:@"avg"];
        //最大值
        NSNumber *H = [tmpArr lastObject];
        [dic setObject:H forKey:@"max"];
        //最小值
        NSNumber *L = [tmpArr firstObject];
        [dic setObject:L forKey:@"min"];
    }
    return dic;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

#pragma 通过最大最小值计算Y轴每个区间的值
- (NSMutableArray *)CalculateYWithHigh:(int)H andLow:(int)L andArray:(NSArray *)array
{
    NSMutableArray *Yarray = [NSMutableArray new];
    
    NSComparator finderSort = ^(id string1,id string2){
        
        if ([string1 integerValue] > [string2 integerValue]) {
            return (NSComparisonResult)NSOrderedDescending;
        }else if ([string1 integerValue] < [string2 integerValue]){
            return (NSComparisonResult)NSOrderedAscending;
        }
        else
            return (NSComparisonResult)NSOrderedSame;
    };
    NSArray *resultArray = [array sortedArrayUsingComparator:finderSort];
    int maxNumber = [[resultArray lastObject]floatValue];
    if (maxNumber<H) {
        maxNumber = H;
    }
    int max = (maxNumber+4)/4*4;
    int minNumber = [[resultArray firstObject]floatValue];
    if (minNumber>L) {
        minNumber = L;
    }
    int min = (minNumber-10)/10*10;
    if (min<0) {
        min =0;
    }
     NSString *maxNumStr = [NSString stringWithFormat:@"%d",max];
    NSString *minNumStr = [NSString stringWithFormat:@"%d",min];

    float midNum = (max+min)/2;
    NSString *midNumStr = [NSString stringWithFormat:@"%1.f",midNum];
    float secMinNum = (min+midNum)/2;
    NSString *secMinNumStr = [NSString stringWithFormat:@"%1.f",secMinNum];
    float secMaxNum = (max+midNum)/2;
    NSString *secMaxNumStr = [NSString stringWithFormat:@"%1.f",secMaxNum];
    Yarray[0] = minNumStr;
    Yarray[1] = secMinNumStr;
    Yarray[2] = midNumStr;
    Yarray[3] = secMaxNumStr;
    Yarray[4] = maxNumStr;
    return Yarray;
}
#pragma 计步Y轴每个区间
- (NSMutableArray *)WalkCalculateYWithMaxNum:(int)YmaxNum
{
    NSMutableArray *Yarray = [NSMutableArray new];
    NSString *maxNumStr;
    //如果步数大于1000步则以k为计量单位，否则以1为单位
    if (YmaxNum>1000) {
        float YmaxNumTmp = YmaxNum/1000.0;
        maxNumStr = [NSString stringWithFormat:@"%.1fk",YmaxNumTmp];
    }else{
        maxNumStr = [NSString stringWithFormat:@"%d",YmaxNum];
    }
    int YminNum = 0;
    NSString *minNumStr = [NSString stringWithFormat:@"%d",YminNum];
    int YmidNum = (YmaxNum-YminNum)/2;
    NSString *midNumStr;
    if (YmidNum>1000) {
        float YmaxNumTmp = YmidNum/1000.0;
        midNumStr = [NSString stringWithFormat:@"%.1fk",YmaxNumTmp];
    }else{
        midNumStr = [NSString stringWithFormat:@"%d",YmidNum];
    }
    
    
    int YsecMinNum = (YmaxNum-YmidNum)/2;
    NSString *secMinNumStr;
    if (YsecMinNum>1000) {
        float YsecMinNumTmp = YsecMinNum/1000.0;
        secMinNumStr = [NSString stringWithFormat:@"%.1fk",YsecMinNumTmp];
    }else
    {
        secMinNumStr = [NSString stringWithFormat:@"%d",YsecMinNum];
    }
    
    
    int YsecMaxNum = (YmidNum/2+YmidNum);
    NSString *secMaxNumStr;
    if (YsecMaxNum>1000) {
        float YsecMaxNumTmp = YsecMaxNum/1000.0;
        secMaxNumStr = [NSString stringWithFormat:@"%.1fk",YsecMaxNumTmp];
    }else
    {
        secMaxNumStr = [NSString stringWithFormat:@"%d",YsecMaxNum];
    }
    Yarray[0] = minNumStr;
    Yarray[1] = secMinNumStr;
    Yarray[2] = midNumStr;
    Yarray[3] = secMaxNumStr;
    Yarray[4] = maxNumStr;
    return Yarray;
}
#pragma  字符串数组排序（计步）
- (NSArray *)sortedArrayWithArray:(NSMutableArray *)array
{
    //字符串转NSNumber对象
    NSMutableArray *descArr = [NSMutableArray new];
    for (NSString *tmpStr in array) {
        NSNumber * nums = @([tmpStr integerValue]);
        [descArr addObject:nums];
    }
    //对数组排序
    NSArray *sortedArray = [descArr sortedArrayUsingSelector:@selector(compare:)];
    return sortedArray;
}
#pragma -mark 通过开始日期获取本周后面六天的日期
- (NSArray *)getAfterSevenDaysWithStartDate:(NSDate *)startDate
{
    NSMutableArray *arrDares =[NSMutableArray array];
    for (int i = 0; i < 7; i++) {
        NSDate *lastDay = [NSDate dateWithTimeInterval:24*60*60*i sinceDate:startDate];
        NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
        [dateformatter setDateFormat:@"YYYY-MM-dd"];
        NSString * locationString = [dateformatter stringFromDate:lastDay];
        NSArray *arr = [locationString componentsSeparatedByString:@"-"];
        [arrDares addObject:[NSString stringWithFormat:@"%@",arr[2]]];
    }
    return arrDares;
}

@end
